package com.jsyh.shopping.uilibrary.views;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;

public class LoadMoreScrollView extends ScrollView {

	OnBorderListener onBorderListener;

	public boolean loadding = false;

	public LoadMoreScrollView(Context context) {
		super(context);
	}

	public LoadMoreScrollView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	protected void onScrollChanged(int x, int y, int oldx, int oldy) {
		super.onScrollChanged(x, y, oldx, oldy);

		doOnBorderListener();
	}

	private void doOnBorderListener() {
		if (getChildAt(0) != null
				&& getChildAt(0).getMeasuredHeight() <= getScrollY()
						+ getHeight()) {
			if (onBorderListener != null && !loadding) {
				//loadding = true;
				onBorderListener.onBottom();
			}
		} else if (getScrollY() == 0) {
			if (onBorderListener != null) {
				onBorderListener.onTop();
			}
		}
	}

	public void setOnBorderListener(OnBorderListener onBorderListener) {
		this.onBorderListener = onBorderListener;
	}

	
	public static interface OnBorderListener {

		/**
		 * Called when scroll to bottom
		 */
		public void onBottom();

		/**
		 * Called when scroll to top
		 */
		public void onTop();
	}
}
